package gateway

import (
	"github.com/Unixeno/TheMoon/common/util"
	"github.com/gorilla/mux"
	"net/http"
	"strconv"
)

// Resource Amount
//
// swagger:parameters GenMoonID
type AmountParam struct {
	// 资源数量
	//
	// in: path
	Amount int `json:"amount"`
}

// ID列表
//
// swagger:response IDResponse
type IDResponse struct {
	// in: body
	Body []string
}

// swagger:route GET /tools/moon_id/{amount} tools GenMoonID
//
// GenMoonID
//
// 添加一个Moon节点
//
//     Responses:
//       200: IDResponse
func GenMoonID(w http.ResponseWriter, r *http.Request) {
	params := mux.Vars(r)
	amountReq := params["amount"]
	if amountReq == "" {
		amountReq = "1"
	}
	amount, _ := strconv.Atoi(amountReq)
	ids := make([]string, 0, amount)
	for i := 0; i < amount; i++ {
		ids = append(ids, util.GenMoonID())
	}
	WriteResponse(w, ids)
}
